The code below assumes that a PrintJob is already open.
PEGetNTables PEGetNthTableType PEGetNthTableLogOnInfo PESetNthTableLogOnInfo PETestNthTableConnectivity
uses CRDelphi; {Stringlists to store the LogOn information} var sServerName, sUserID, sPassword, sDatabaseName, {These last three are not necessary: they hold Table descriptive information} sDLLName, sDescriptiveName, sTableType : TStringList; procedure GetLogOnInfo; var LogInfo : PELogOnInfo; TableType : PETableType; nTables, nTable : smallint; begin LogInfo.StructSize := SizeOf(PELogOnInfo); TableType.StructSize := SizeOf(PETableType); {Loop through the tables} nTables := PEGetNTables(PrintJob); if nTables =-1 then {Do Error Handler}; {Create storage StringLists} sServerName := TStringList.Create; sUserID := TStringList.Create; sPassword := TStringList.Create; sDatabaseName := TStringList.Create; sDLLName := TStringList.Create; sDescriptiveName := TStringList.Create; sTableType := TStringList.Create; {Loop through the tables} for nTable := 0 to (nTables - 1) do begin if not PEGetNthTableType(PrintJob, nTable, TableType) then {Do Error Handler}; {Try to find an SQL table} if (TableType.DBType = PE_DT_SQL) or (TableType.DBType = PE_DT_SQL_STORED_PROCEDURE) then begin if not PEGetNthTableLogOnInfo(PrintJob, nTable, LogInfo) then {Do Error Handler}; sServerName.Add(StrPas(@LogInfo.ServerName)); sUserID.Add(StrPas(@LogInfo.UserID)); {Password will be blank since it is not stored in the Report} sPassword.Add(StrPas(@LogInfo.Password)); sDatabaseName.Add(StrPas(@LogInfo.DatabaseName)); sDLLName.Add(StrPas(@TableType.DLLName)); sDescriptiveName.Add(StrPas(@TableType.DescriptiveName)); sTableType.Add(IntToStr(TableType.DBType)); end; end; end; procedure SetLogOnInfo; var LogInfo : PELogOnInfo; nTable : smallint; nTables : smallint; nTable : integer; sSN, sUID, sDBN : string; Changed : boolean; begin LogInfo.StructSize := SizeOf(PELogOnInfo); nTable := 0; {Get number of tables} nTables := PEGetNTables(PrintJob); if nTables =-1 then {Do Error Handler}; {Loop through the LogOnInfo items} for nTable := 0 to (nTables - 1) do begin Changed := False; {Get the LogOnInfo from the Report} if not PEGetNthTableLogOnInfo(PrintJob, nTable, LogInfo) then {Do Error Handler}; {ServerName} sSN := StrPas(@LogInfo.ServerName); if CompareStr(sSN, sServerName[nTable]) <> 0 then begin if sServerName[nTable] <> '' then StrPCopy(@LogInfo.ServerName, sServerName[nTable]); Changed := True; end; {UserID} sUID := StrPas(@LogInfo.UserID); if CompareStr(sUID, sUserID[nTable]) <> 0 then begin if sUserID[nTable] <> '' then StrPCopy(@LogInfo.UserID, sUserID[nTable]); Changed := True; end; {Password} if sPassword[nTable] <> '' then begin StrPCopy(@LogInfo.Password, sPassword[nTable]); Changed := True; end; {DatabaseName} sDBN := StrPas(@LogInfo.DatabaseName); if CompareStr(sDBN, sDatabaseName[nTable]) <> 0 then begin if sDatabaseName[nTable] <> '' then StrPCopy(@LogInfo.DatabaseName, sDatabaseName[nTable]); Changed := True; end; {Send the LogOnInfo to the Report} if Changed then begin if not PESetNthTableLogOnInfo(PrintJob, nTable, LogInfo, False) then {Do Error Handler}; end; end; {Free storage StringLists} sServerName.Free; sUserID.Free; sPassword.Free; sDatabaseName.Free; sDLLName.Free; sDescriptiveName.Free; sTableType.Free; end; {LogOn Information can be tested before running a Report to confirm that a connection can be established with the Server} function TestLogOnInfo(nTable: smallint) : boolean; var LogInfo : PELogOnInfo; begin Result := False; LogInfo.StructSize := SizeOf(PELogOnInfo); StrPCopy(@LogInfo.ServerName, sServerName[nTable]); StrPCopy(@LogInfo.UserID, sUserID[nTable]); StrPCopy(@LogInfo.Password, sPassword[nTable]); StrPCopy(@LogInfo.DatabaseName, sDatabaseName[nTable]); {Set LogOnInfo} if not PESetNthTableLogOnInfo(PrintJob, nTable, LogInfo, False) then {Do Error Handler}; {Test LogOn} Result := PETestNthTableConnectivity(PrintJob, nTable); end;
Seagate Software IMG Holdings, Inc. http://www.seagatesoftware.com Support services: http://support.seagatesoftware.com |